package com.test.test1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class HelloInvocationHandler implements InvocationHandler {
    private Object target;

    public HelloInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //方法调用前的处理
        System.out.println("调用方法"+method.getName()+"之前的逻辑");
        Object result = null;
        if(target != null){
            result = method.invoke(target,args);
        }
        // 方法调用后处理
        System.out.println("调用方法 " + method.getName() + " 之后的逻辑");
        return result;
    }
}
